<h1>Listing users</h1>
<%= form_tag users_path, :method => 'get', :id => "users_search" do %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>
  </p>
<% end %>
<%= hidden_field_tag :direction, params[:direction] %>
<%= hidden_field_tag :sort, params[:sort] %>
<table>
	<tr>
	  <th><%= sortable "name","Nombre" %></th>
	  <th><%= sortable "last_name","Apellido" %></th>
	  <th><%= sortable "rut" %></th>
	  <th><%= sortable "email" %></th>
      <th></th>
	  <th></th>
      <th></th>
	  <th></th>
	  <th></th>
	</tr>

<% @users.each do |user| %>
  <tr>
	<% if can? :manage, user %>
    <td><%= user.name %></td>
    <td><%= user.last_name %></td>
    <td><%= user.rut %></td>
	<td><%= user.email %></td>
    <td><%= link_to 'Mostrar', user %></td>
   	<td><%= link_to 'Editar', edit_user_path(user) %></td>
	<%= form_for(user) do |f| %>
	  <%= f.hidden_field :deleted,:value => user.id%>
	  <td><%= f.submit "Eliminar" %></td>
	<% end %>
	<%if !user.confirmation%>
	<%= form_for(user) do |f| %>
	  <%= f.hidden_field :confirmation,:value => true%>
	  <td><%= f.submit "Confirmar" %></td>
	<% end %>
	<%else%>
	<td></td>
	<%end%>
	<%if user.locked or user.faild_attempts>3%>
	<%= form_for(user) do |f| %>
	  <%= f.hidden_field :locked,:value => false%>
	<%= f.hidden_field :faild_attempts,:value => 0%>
	  <td><%= f.submit "Desbloquear" %></td>
	<% end %>
	<%else%>
	<td></td>
	<%end%>
	
  	<% end %>
  </tr>
<% end %>
</table>
<%= will_paginate @products %>
